﻿package frEngine.loaders.particleSub.particleInstance
{
    import __AS3__.vec.*;
    import flash.geom.*;

    public class CrossPlaneParticle extends MeshBase
    {
        private var _w:Number;
        private var _h:Number;
        private var _axis:String;
        private static const p0:Point = new Point();
        private static const p1:Point = new Point();
        private static const p2:Point = new Point();
        private static const p3:Point = new Point();
        private static const center:Point = new Point(0.5, 0.5);

        public function CrossPlaneParticle(param1:Number, param2:Number, param3:String = "y", param4:Number = 0)
        {
            super(8, 5, false, false);
            this._axis = param3;
            this._w = param1;
            this._h = param2;
            vertexVector = this.getVertexVector(param4);
            indexVector = this.getIndexVector();
            return;
        }// end function

        private function getVertexVector(param1:Number) : Vector.<Number>
        {
            var _loc_2:* = new Vector.<Number>;
            var _loc_3:* = this._w / 2;
            var _loc_4:* = this._h / 2;
            var _loc_5:Number = 1;
            var _loc_6:Number = 0;
            p0.x = 1;
            p0.y = 1;
            p1.x = 0;
            p1.y = 1;
            p2.x = 0;
            p2.y = 0;
            p3.x = 1;
            p3.y = 0;
            if (param1 > 0)
            {
                rotate(center, param1, p0, p0);
                rotate(center, param1, p1, p1);
                rotate(center, param1, p2, p2);
                rotate(center, param1, p3, p3);
            }
            if (this._axis == "y")
            {
                _loc_2.push(_loc_3, _loc_4, 0, p0.x, p0.y);
                _loc_2.push(_loc_3, -_loc_4, 0, p1.x, p1.y);
                _loc_2.push(-_loc_3, -_loc_4, 0, p2.x, p2.y);
                _loc_2.push(-_loc_3, _loc_4, 0, p3.x, p3.y);
                _loc_2.push(0, _loc_4, _loc_3, p0.x, p0.y);
                _loc_2.push(0, _loc_4, -_loc_3, p3.x, p3.y);
                _loc_2.push(0, -_loc_4, -_loc_3, p2.x, p2.y);
                _loc_2.push(0, -_loc_4, _loc_3, p1.x, p1.y);
            }
            else if (this._axis == "z")
            {
                _loc_2.push(_loc_3, 0, _loc_4, p0.x, p0.y);
                _loc_2.push(_loc_3, 0, -_loc_4, p1.x, p1.y);
                _loc_2.push(-_loc_3, 0, -_loc_4, p2.x, p2.y);
                _loc_2.push(-_loc_3, 0, _loc_4, p3.x, p3.y);
                _loc_2.push(0, _loc_3, _loc_4, p0.x, p0.y);
                _loc_2.push(0, -_loc_3, _loc_4, p3.x, p3.y);
                _loc_2.push(0, -_loc_3, -_loc_4, p2.x, p2.y);
                _loc_2.push(0, _loc_3, -_loc_4, p1.x, p1.y);
            }
            else
            {
                _loc_2.push(_loc_4, _loc_3, 0, p0.x, p0.y);
                _loc_2.push(-_loc_4, _loc_3, 0, p1.x, p1.y);
                _loc_2.push(-_loc_4, -_loc_3, 0, p2.x, p2.y);
                _loc_2.push(_loc_4, -_loc_3, 0, p3.x, p3.y);
                _loc_2.push(_loc_4, 0, _loc_3, p0.x, p0.y);
                _loc_2.push(_loc_4, 0, -_loc_3, p3.x, p3.y);
                _loc_2.push(-_loc_4, 0, -_loc_3, p2.x, p2.y);
                _loc_2.push(-_loc_4, 0, _loc_3, p1.x, p1.y);
            }
            return _loc_2;
        }// end function

        private function getIndexVector() : Vector.<uint>
        {
            var _loc_3:int = 0;
            var _loc_1:* = new Vector.<uint>;
            var _loc_2:int = 0;
            while (_loc_2 < 2)
            {
                
                _loc_3 = _loc_2 * 4;
                _loc_1.push(_loc_3, (_loc_3 + 1), _loc_3 + 2);
                _loc_1.push(_loc_3 + 2, _loc_3 + 3, _loc_3);
                _loc_2++;
            }
            return _loc_1;
        }// end function

        public function get height() : Number
        {
            return this._h;
        }// end function

        public function get width() : Number
        {
            return this._w;
        }// end function

        private static function rotate(param1:Point, param2:Number, param3:Point, param4:Point = null) : Point
        {
            var _loc_5:* = Math.PI / 180 * param2;
            if (!param4)
            {
                param4 = new Point();
            }
            var _loc_6:* = param3.x - param1.x;
            var _loc_7:* = param3.y - param1.y;
            param4.x = _loc_6 * Math.cos(_loc_5) - _loc_7 * Math.sin(_loc_5) + param1.x;
            param4.y = _loc_7 * Math.cos(_loc_5) + _loc_6 * Math.sin(_loc_5) + param1.y;
            return param4;
        }// end function

    }
}
